/**
 * 
 */
package com.dalonedrow.module.chivalrysorcery.systems;

import com.dalonedrow.engine.sprite.base.SimpleColor;
import com.dalonedrow.engine.sprite.base.SimpleVector3;
import com.dalonedrow.engine.systems.JOGLErrorHandler;
import com.dalonedrow.engine.systems.base.Interactive;
import com.dalonedrow.globalvariables.constants.hq.GlobalConstants;
import com.dalonedrow.module.chivalrysorcery.rpg.ChivSorcInteractiveObject;
import com.dalonedrow.module.chivalrysorcery.rpg.ChivSorcNPCData;
import com.dalonedrow.rpg.base.flyweights.Scriptable;
import com.dalonedrow.rpg.base.flyweights.Spell;
import com.dalonedrow.rpg.base.systems.NPC;

/**
 * @author Donald
 */
public class ChivSorcNPC implements NPC<ChivSorcInteractiveObject, ChivSorcNPCData,
		Scriptable<ChivSorcInteractiveObject>> {
	/** the singeton instance of {@link ChivSorcNPC}. */
	private static ChivSorcNPC	instance;

	/**
	 * Gets the one and only instance of {@link ChivSorcNPC}.
	 * @return {@link ChivSorcNPC}
	 */
	public static ChivSorcNPC getInstance() {
		if (ChivSorcNPC.instance == null) {
			ChivSorcNPC.instance = new ChivSorcNPC();
		}
		return ChivSorcNPC.instance;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public float angularDifference(float a1, float a2) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public long applyCuts(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void applyPhysics() {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void behaviourChange(ChivSorcInteractiveObject io, long behavior,
			long behavior_param) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void behaviourReset(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void behaviourResetAll() {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void behaviourStack(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void behaviourUnStack(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void changeMoveMode(ChivSorcInteractiveObject io, long MOVEMODE) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void checkNPC(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void checkNPCEx(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void checkUnderWaterIO(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void computeNPCFullStats(final ChivSorcInteractiveObject io)
			throws Exception {
		System.out.println("**********************");
		System.out.println("computeNPCFullStats");
		ChivSorcNPCData npc = io.getNPCData();
		// clear all modifications
		npc.setModAttack(0);
		npc.setModBody(0);
		npc.setModDefend(0);
		npc.setModMind(0);
		npc.setModMovement(0);
		npc.setModMaxBody(0);
		npc.setModMaxMind(0);

		// IDENTIFY ALL EQUIPMENT AND APPLY MODS
		ChivSorcEquipment.getInstance().identifyAll(io);
		// Check for Equipment Modifiers to Attributes
		npc.adjModAttack(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_ATTACK,
				npc.getBaseAttack()
				));
		npc.adjModBody(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_BODY,
				npc.getBaseBody()
				));
		npc.adjModDefend(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_DEFEND,
				npc.getBaseDefend()
				));
		npc.adjModMind(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_MIND,
				npc.getBaseMind()
				));
		npc.adjModMovement(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_MOVEMENT,
				npc.getBaseMovement()
				));
		npc.adjModMaxBody(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_MAX_BODY,
				npc.getBaseMaxBody()
				));
		npc.adjModMaxMind(ChivSorcEquipment.getInstance().getEquipmentModifier(
				io,
				GlobalConstants.IO_EQUIPITEM_ELEMENT_MAX_MIND,
				npc.getBaseMaxMind()
				));
		// Check for Equipment Modifiers to Skills
		// NOT USED
		// Check for Equipment Percent Modifiers to Skills
		// NOT USED
		// APPLY MODS FOR ALL SPELLS
		for (int i = 0; i < io.getNumberOfSpellsOn(); i++) {
			int spellId = io.getSpellOn(i);
			Spell spell = ChivSorcSpells.getInstance().getSpell(spellId);
			if (spell.exists()) {
				switch (spell.getType()) {
				default:
					break;
				}
			}
		}

		// SET FULL ATTRIBUTES
		npc.setFullAttack(npc.getBaseAttack() + npc.getModAttack());
		npc.setFullBody(npc.getBaseBody() + npc.getModBody());
		npc.setFullDefend(npc.getBaseDefend() + npc.getModDefend());
		npc.setFullMind(npc.getBaseMind() + npc.getModMind());
		npc.setFullMovement(npc.getBaseMovement() + npc.getModMovement());
		npc.setFullMaxBody(npc.getBaseMaxBody() + npc.getModMaxBody());
		npc.setFullMaxMind(npc.getBaseMaxMind() + npc.getModMaxMind());

		// SET PAPER DOLL
		/*
		 * if (pc.getBaseSize() >= 9 && pc.getBaseSize() <= 12) {
		 * pc.setHeight(RPGConsts.HEIGHT_00AVERAGE); } else if (pc.getBaseSize()
		 * >= 13) { pc.setHeight(RPGConsts.HEIGHT_01TALL); } if (pc.getGender()
		 * == RPGConsts.GENDER_FEMALE) { if (pc.getBaseConstitution() == 18) {
		 * pc.setMuscle(RPGConsts.MUSCLE_01MUSCULAR); } else if
		 * (pc.getBaseStrength() + pc.getBaseConstitution() >= 32) {
		 * pc.setMuscle(RPGConsts.MUSCLE_01MUSCULAR); } else {
		 * pc.setMuscle(RPGConsts.MUSCLE_00AVERAGE); } } else { if
		 * (pc.getBaseStrength() == 18) {
		 * pc.setMuscle(RPGConsts.MUSCLE_01MUSCULAR); } else if
		 * (pc.getBaseStrength() + pc.getBaseDexterity() >= 32) {
		 * pc.setMuscle(RPGConsts.MUSCLE_01MUSCULAR); } else {
		 * pc.setMuscle(RPGConsts.MUSCLE_00AVERAGE); } }
		 */
		npc.notifyWatchers();
		System.out.println("**********************");
		System.out.println("end computeNPCFullStats");
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void computeTolerance(ChivSorcInteractiveObject io, long targ, float[] dst) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return super.equals(obj);
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void faceTarget(final ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void finalize() throws Throwable {
		// TODO Auto-generated method stub
		super.finalize();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int getCutFlag(char[] str) {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public long getCutSelection(ChivSorcInteractiveObject io, short flag) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ChivSorcInteractiveObject getFirstNPCInSight(ChivSorcInteractiveObject ioo) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * Gets a "fresh" NPC.
	 * @param script the script defining the NPC
	 * @return {@link ChivSorcInteractiveObject}
	 * @throws Exception if an erro occurs
	 */
	@Override
	public ChivSorcInteractiveObject getFreshNPC(
			final Scriptable<ChivSorcInteractiveObject> script) throws Exception {
		ChivSorcInteractiveObject io =
				(ChivSorcInteractiveObject) Interactive.getInstance().getNewIO();
		io.setNPCData(new ChivSorcNPCData());
		io.setScript(script);
		script.setIO(io);
		ChivSorcScript.getInstance().sendInitScriptEvent(io);
		return io;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public float getIOHeight(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public float getIORadius(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void getMaterialString(char[] origin, char[] dest) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public float getTrueTargetDist(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return super.hashCode();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isAlreadyCut(ChivSorcInteractiveObject io, short fl) {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isDeadNPC(final ChivSorcInteractiveObject io) {
		boolean deadSoFar = true;
		// an NPC is dead if...
		// 1. it is not null
		// 2. it has the npc flag
		// 3. its life is <= 0
		// - OR -
		// 4. it has the "DEAD" main event
		if (io == null) {
			deadSoFar = false;
		}
		if (deadSoFar) {
			if (!io.hasIOFlag(GlobalConstants.IO_03_NPC)) {
				deadSoFar = false;
			}
			if (deadSoFar) {
				try {
					ChivSorcNPC.getInstance().computeNPCFullStats(io);
				} catch (Exception ex) {
					JOGLErrorHandler.getInstance().fatalError(ex);
				}
				if (io.getNPCData().getFullBody() > 0) {
					deadSoFar = false;
				}
				if (!deadSoFar) {
					if (io.getMainevent() != null
							&& io.getMainevent().equalsIgnoreCase("DEAD")) {
						deadSoFar = true;
					}
				}
			}
		}
		return deadSoFar;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isPlayerStriking() {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void killSpellLaunch(final ChivSorcInteractiveObject io) {
		if (io != null) {
			/*
			 * Not used if (io->flarecount) { for (long i = 0; i < MAX_FLARES;
			 * i++) { if ((flare[i].exist) && (flare[i].io == io)) flare[i].io =
			 * NULL; } }
			 */
			io.getSpellcastData().setCastingspell(-1);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageAnims(ChivSorcInteractiveObject io, float TOLERANCE) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageAnimsEnd(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageFight(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageIgnition(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageIgnition_2(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageNONFight(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageNPCMovement(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void managePoison(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void needStepSound(ChivSorcInteractiveObject io, SimpleVector3 pos,
			float volume, float power) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void recomputeCutFlags(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void releasePathFindInfo(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void revive(ChivSorcInteractiveObject io, long flags) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setStat(ChivSorcInteractiveObject io, char[] statname, float value) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void spawnAudibleSound(SimpleVector3 pos, ChivSorcInteractiveObject source,
			float factor, float presence) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void spawnBlood3(SimpleVector3 pos, float dmgs, SimpleColor col, long vert,
			ChivSorcInteractiveObject io, long flags) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void spawnMember(ChivSorcInteractiveObject ioo, long num) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void spawnSplat(SimpleVector3 pos, float dmgs, SimpleColor col, long vert,
			ChivSorcInteractiveObject io, long flags) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void stareAtTarget(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void strikeStartTickCount(ChivSorcInteractiveObject io) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void tryAndCheckAnim(ChivSorcInteractiveObject io, long animnum, long layer) {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean tryIOAnimMove(ChivSorcInteractiveObject io, long animnum) {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void tryToCutSomething(ChivSorcInteractiveObject target, SimpleVector3 pos) {
		// TODO Auto-generated method stub

	}
}
